 <?php defined('SYSPATH') or die('No direct script access.'); ?> 
<div class="center_title_bar"><?php echo 'Cart' ?></div>
 <?php $total = 0; ?>
 <?php $index = 0;?>
 <?php $amounts = Cookie::get('amounts');?>
 <?php $amounts = explode(',',$amounts);?>
 <?php if (! empty($items)){ ?>
		<table>
			<tr>
				<td> <?php echo Form::label('itemname', 'Item Name'); ?> </td>
				<td> <?php echo Form::label('quantity', 'Quantity '); ?> </td>
				<td> <?php echo Form::label('Price', 'Price '); ?> </td>
			</tr>
	 <?php foreach($items as $item): ?>
	 <?php $price = $item->price*$amounts[$index]?>
	 <?php foreach ($item->promotions->find_all() as $promotion): ?>
		<?php if($promotion->discount_type == 'percent'):?>
			<?php if(($promotion->starting_date < strtotime('now')) && (strtotime('now') < $promotion->ending_date)): ?>
				<?php $price = $price*(1 - ($promotion->discount/100)); ?>
			<?php endif; ?>
		<?php endif; ?>
		<?php if($promotion->discount_type == 'amount'): ?>
			<?php if(($promotion->starting_date < strtotime('now')) && (strtotime('now') < $promotion->ending_date)): ?>
				<?php $price = $price - $promotion->discount;?>
		<?php endif; ?>
		<?php endif; ?>
	<?php endforeach; ?>
		
		<div id="itembox">
			

				<tr>
					<td>
						<?php echo HTML::anchor('item/item/sitem/'.$item->id, $item->name); ?>
					</td>
					<td>
						<?php echo Form::open('cart/quantity', array('method'=>'get'));?>
						<?php echo Form::hidden('index', $index); ?>
						<?php echo Form::input('quantity', $amounts[$index], array('size'=>3)); ?>
						<?php echo Form::submit(NULL, 'Change Quantity'); ?><br>
						<?php echo Form::close();?>
					</td>
					<td>
						<?php $promotions = $item->promotions->find_all()->as_array();?>
						<?php if (empty($promotions)): ?>
							<div class="prod_price_big"><span class="price"><?php echo '$'.$item->price; ?></span>
						<?php else: ?>
							<div class="prod_price_big"><span class="reduce"><?php echo '$'.$item->price; ?></span>
							<span class="price"><?php echo '$'.$price; ?></span>
						<?php endif; ?>
						</div>
					</td>				
					<td>
						<?php echo HTML::anchor('cart/remove/'.$index, 'Remove from cart'); ?>
					</td>
				</tr>
			
				<?php $total += $price; ?>			
				<?php $index ++; ?>
				</div>
		<?php endforeach; ?>
		</table>

		<?php echo Form::label('total', 'Total:'); ?>
		<span class="price"><?php echo '$'.$total; ?></span>
		<?php echo Form::open('cart/payment', array('method' => 'post')); ?>
			<?php foreach($items as $item):?>
				<?php echo Form::hidden('order[]', $item->id); ?>
			<?php endforeach; ?>
			<?php echo Form::hidden('total', $total); ?>
			<?php echo Form::submit(NULL, 'Place Order'); ?>
		<?php echo Form::close(); ?>
		<?php } 
		else
		{
			echo 'Your cart is empty.';
		} ?>

 